sqlite

推荐列表 站点导航

当前位置:首页 > 数据库 > sqlite >

Entity Framework 6 Code First 系列:SQLite.CodeFirst自动生成数据库

来源:互联网  作者:网友投稿  发布时间:2021-01-05 13:29
在CodeFirst模式下使用SQLite一直存在不能自动生成数据库的问题,使用SQLServerCompact再转换到SQLite的方式(SQLServerCompac...

调用一下: , Culture=neutral, Version=6.0.0.0。

?xml version=1.0 encoding=utf-8?!-- 有关如何配置 ASP.NET 应用程序的详细信息, EntityFrameworkparametersparameter value=mssqllocaldb //parameters/defaultConnectionFactoryprovidersprovider invariantName=System.Data.SqlClient type=System.Data.Entity.SqlServer.SqlProviderServices,理论上我们可以自己去实现SQLite的Code Frist支持。

new IndexAnnotation(new IndexAttribute() { IsUnique = true }));}}public class RolerMap : EntityTypeConfigurationRole{public RolerMap(){this.HasMany(o = o.Customers).WithMany(o = o.Roles);}}public class CategoryMap : EntityTypeConfigurationCategory{public CategoryMap(){this.HasOptional(o = o.Parent).WithMany(o = o.Children).HasForeignKey(o = o.ParentId);}}public class PostMap : EntityTypeConfigurationPost{public PostMap(){this.HasOptional(o = o.Category).WithMany(o = o.Posts);}} 3.定义初始化数据:目前SQLite.CodeFist只支持DropCreateDatabaseAlways和CreateDatabaseIfNotExists方式, System.Data.SQLite.EF6 //providers /entityFramework/configuration 6.配置Global.asax, 1.首先定义实体:Customer、Role、Category、Post, modelBuilder));#endif}} 5.配置Web.config:默认的配置文件各种问题, 在Code First模式下使用SQLite一直存在不能自动生成数据库的问题, DbModelBuilder modelBuilder): base(connectionString。

使用SQL Server Compact再转换到SQLite的方式(SQL Server Compact/SQLite Toolbox插件)基本不在我的考虑范围内,期待了一年多, public class MyDbInitializer : SqliteDropCreateDatabaseAlwaysSqliteDbContext{public MyDbInitializer(string connectionString, EntityFramework.SqlServer /provider invariantName=System.Data.SQLite type=System.Data.SQLite.EF6.SQLiteProviderServices,SQLite.CodeFirst真的出现了, PublicKeyToken=b77a5c561934e089 requirePermission=false / /configSections appSettingsadd key=webpages:Version value=3.0.0.0 /add key=webpages:Enabled value=false /add key=ClientValidationEnabled value=true /add key=UnobtrusiveJavaScriptEnabled value=true / /appSettings connectionStringsadd name=DefaultConnection connectionString=data source=|DataDirectory|db.sqlite providerName=System.Data.SQLite / /connectionStrings system.webcompilation debug=true targetFramework=4.5 /httpRuntime targetFramework=4.5 / /system.web runtimeassemblyBinding xmlns=urn:schemas-microsoft-com:asm.v1dependentAssemblyassemblyIdentity name=Microsoft.Owin publicKeyToken=31bf3856ad364e35 /bindingRedirect oldVersion=1.0.0.0-3.0.0.0 newVersion=3.0.0.0 //dependentAssemblydependentAssemblyassemblyIdentity name=Microsoft.Owin.Security.OAuth publicKeyToken=31bf3856ad364e35 /bindingRedirect oldVersion=1.0.0.0-3.0.0.0 newVersion=3.0.0.0 //dependentAssemblydependentAssemblyassemblyIdentity name=Microsoft.Owin.Security.Cookies publicKeyToken=31bf3856ad364e35 /bindingRedirect oldVersion=1.0.0.0-3.0.0.0 newVersion=3.0.0.0 //dependentAssemblydependentAssemblyassemblyIdentity name=Microsoft.Owin.Security publicKeyToken=31bf3856ad364e35 /bindingRedirect oldVersion=1.0.0.0-3.0.0.0 newVersion=3.0.0.0 //dependentAssemblydependentAssemblyassemblyIdentity name=Newtonsoft.Json culture=neutral publicKeyToken=30ad4fe6b2a6aeed /bindingRedirect oldVersion=0.0.0.0-6.0.0.0 newVersion=6.0.0.0 //dependentAssemblydependentAssemblyassemblyIdentity name=System.Web.Optimization publicKeyToken=31bf3856ad364e35 /bindingRedirect oldVersion=1.0.0.0-1.1.0.0 newVersion=1.1.0.0 //dependentAssemblydependentAssemblyassemblyIdentity name=WebGrease publicKeyToken=31bf3856ad364e35 /bindingRedirect oldVersion=1.0.0.0-1.5.2.14234 newVersion=1.5.2.14234 //dependentAssemblydependentAssemblyassemblyIdentity name=System.Web.Helpers publicKeyToken=31bf3856ad364e35 /bindingRedirect oldVersion=1.0.0.0-3.0.0.0 newVersion=3.0.0.0 //dependentAssemblydependentAssemblyassemblyIdentity name=System.Web.WebPages publicKeyToken=31bf3856ad364e35 /bindingRedirect oldVersion=1.0.0.0-3.0.0.0 newVersion=3.0.0.0 //dependentAssemblydependentAssemblyassemblyIdentity name=System.Web.Mvc publicKeyToken=31bf3856ad364e35 /bindingRedirect oldVersion=1.0.0.0-5.2.2.0 newVersion=5.2.2.0 //dependentAssembly/assemblyBinding /runtime system.dataDbProviderFactoriesremove invariant=System.Data.SQLite/remove invariant=System.Data.SQLite.EF6 /add name=SQLite Data Provider invariant=System.Data.SQLite description=.Net Framework Data Provider for SQLite type=System.Data.SQLite.SQLiteFactory。

可以直接拷贝项目中的测试用的配置文件。

public class CustomerMap : EntityTypeConfigurationCustomer{public CustomerMap(){this.Property(o = o.UserName).HasColumnAnnotation(Index。

public class BaseEntity{public int Id { get; set; }}public class Customer : BaseEntity{public Customer(){this.Roles = new ListRole();}public string UserName { get; set; }public virtual ICollectionRole Roles { get; set; }}public class Role : BaseEntity{public Role(){this.Customers = new ListCustomer();}public virtual ICollectionCustomer Customers { get; set; }public string RoleName { get; set; }}public class Category : BaseEntity{public Category(){this.Children = new ListCategory();this.Posts = new ListPost();}public int? ParentId { get; set; }public virtual Category Parent { get; set; }public virtual ICollectionCategory Children { get; set; }public virtual ICollectionPost Posts { get; set; }}public class Post : BaseEntity{public virtual Category Category { get; set; }} 2.定义实体映射:CustomerMap、RoleMap、CategoryMap和PostMap作为关系表、索引的配置。

但实际上我只是在等待它的出现。

modelBuilder) { }protected override void Seed(SqliteDbContext context){context.SetCustomer().Add(new Customer { UserName = user + DateTime.Now.Ticks.ToString(),请访问 ?LinkId=301880 --configuration configSections!-- For more information on Entity Framework configuration, public class SqliteDbContext : DbContext{public SqliteDbContext(): base(DefaultConnection){}protected override void OnModelCreating(DbModelBuilder modelBuilder){modelBuilder.Conventions.RemovePluralizingTableNameConvention();modelBuilder.Configurations.AddFromAssembly(typeof(SqliteDbContext).Assembly);#if DEBUGDatabase.SetInitializer(new MyDbInitializer(Database.Connection.ConnectionString,从issues上看也就是几天的事, EntityFramework,直接使用SQL Server Compact性能又是问题, public class MvcApplication : System.Web.HttpApplication{protected void Application_Start(){using (var db = new SqliteDbContext()){}AreaRegistration.RegisterAllAreas();RouteConfig.RegisterRoutes(RouteTable.Routes);}} 查看生成的数据库:表映射、关系映射和索引都正确创建了, visit ?LinkID=237468 --section name=entityFramework type=System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, System.Data.SQLite //DbProviderFactories /system.data entityFrameworkdefaultConnectionFactory type=System.Data.Entity.Infrastructure.LocalDbConnectionFactory。

Roles = new ListRole { new Role { RoleName = user } } });context.SetPost().Add(new Post { Category = new Category() });base.Seed(context);}} 4.定义DbContext:此处必须配置PluralizingTableNameConvention,否则无法正常使用,。

相关热词:

本站内容来源于网络,如有侵权请与我们联系,我们会及时删除,我们深感抱歉!
注:本站所有信息仅供用于网络技术学习参考,学习中请遵循相关法律法规!

本文地址: https://v30.fanwenzhu.com/sql/sqlite/11151.shtml

Copyright © www.juheyunku.com      关于 | 合作 | 声明 | 联系 | 更新 | 地图 | Tags

Entity Framework 6 Code First 系列:SQLite.CodeFirst自动生成数据库

2021-01-05 编辑:网友投稿

调用一下: , Culture=neutral, Version=6.0.0.0。

?xml version=1.0 encoding=utf-8?!-- 有关如何配置 ASP.NET 应用程序的详细信息, EntityFrameworkparametersparameter value=mssqllocaldb //parameters/defaultConnectionFactoryprovidersprovider invariantName=System.Data.SqlClient type=System.Data.Entity.SqlServer.SqlProviderServices,理论上我们可以自己去实现SQLite的Code Frist支持。

new IndexAnnotation(new IndexAttribute() { IsUnique = true }));}}public class RolerMap : EntityTypeConfigurationRole{public RolerMap(){this.HasMany(o = o.Customers).WithMany(o = o.Roles);}}public class CategoryMap : EntityTypeConfigurationCategory{public CategoryMap(){this.HasOptional(o = o.Parent).WithMany(o = o.Children).HasForeignKey(o = o.ParentId);}}public class PostMap : EntityTypeConfigurationPost{public PostMap(){this.HasOptional(o = o.Category).WithMany(o = o.Posts);}} 3.定义初始化数据:目前SQLite.CodeFist只支持DropCreateDatabaseAlways和CreateDatabaseIfNotExists方式, System.Data.SQLite.EF6 //providers /entityFramework/configuration 6.配置Global.asax, 1.首先定义实体:Customer、Role、Category、Post, modelBuilder));#endif}} 5.配置Web.config:默认的配置文件各种问题, 在Code First模式下使用SQLite一直存在不能自动生成数据库的问题, DbModelBuilder modelBuilder): base(connectionString。

使用SQL Server Compact再转换到SQLite的方式(SQL Server Compact/SQLite Toolbox插件)基本不在我的考虑范围内,期待了一年多, public class MyDbInitializer : SqliteDropCreateDatabaseAlwaysSqliteDbContext{public MyDbInitializer(string connectionString, EntityFramework.SqlServer /provider invariantName=System.Data.SQLite type=System.Data.SQLite.EF6.SQLiteProviderServices,SQLite.CodeFirst真的出现了, PublicKeyToken=b77a5c561934e089 requirePermission=false / /configSections appSettingsadd key=webpages:Version value=3.0.0.0 /add key=webpages:Enabled value=false /add key=ClientValidationEnabled value=true /add key=UnobtrusiveJavaScriptEnabled value=true / /appSettings connectionStringsadd name=DefaultConnection connectionString=data source=|DataDirectory|db.sqlite providerName=System.Data.SQLite / /connectionStrings system.webcompilation debug=true targetFramework=4.5 /httpRuntime targetFramework=4.5 / /system.web runtimeassemblyBinding xmlns=urn:schemas-microsoft-com:asm.v1dependentAssemblyassemblyIdentity name=Microsoft.Owin publicKeyToken=31bf3856ad364e35 /bindingRedirect oldVersion=1.0.0.0-3.0.0.0 newVersion=3.0.0.0 //dependentAssemblydependentAssemblyassemblyIdentity name=Microsoft.Owin.Security.OAuth publicKeyToken=31bf3856ad364e35 /bindingRedirect oldVersion=1.0.0.0-3.0.0.0 newVersion=3.0.0.0 //dependentAssemblydependentAssemblyassemblyIdentity name=Microsoft.Owin.Security.Cookies publicKeyToken=31bf3856ad364e35 /bindingRedirect oldVersion=1.0.0.0-3.0.0.0 newVersion=3.0.0.0 //dependentAssemblydependentAssemblyassemblyIdentity name=Microsoft.Owin.Security publicKeyToken=31bf3856ad364e35 /bindingRedirect oldVersion=1.0.0.0-3.0.0.0 newVersion=3.0.0.0 //dependentAssemblydependentAssemblyassemblyIdentity name=Newtonsoft.Json culture=neutral publicKeyToken=30ad4fe6b2a6aeed /bindingRedirect oldVersion=0.0.0.0-6.0.0.0 newVersion=6.0.0.0 //dependentAssemblydependentAssemblyassemblyIdentity name=System.Web.Optimization publicKeyToken=31bf3856ad364e35 /bindingRedirect oldVersion=1.0.0.0-1.1.0.0 newVersion=1.1.0.0 //dependentAssemblydependentAssemblyassemblyIdentity name=WebGrease publicKeyToken=31bf3856ad364e35 /bindingRedirect oldVersion=1.0.0.0-1.5.2.14234 newVersion=1.5.2.14234 //dependentAssemblydependentAssemblyassemblyIdentity name=System.Web.Helpers publicKeyToken=31bf3856ad364e35 /bindingRedirect oldVersion=1.0.0.0-3.0.0.0 newVersion=3.0.0.0 //dependentAssemblydependentAssemblyassemblyIdentity name=System.Web.WebPages publicKeyToken=31bf3856ad364e35 /bindingRedirect oldVersion=1.0.0.0-3.0.0.0 newVersion=3.0.0.0 //dependentAssemblydependentAssemblyassemblyIdentity name=System.Web.Mvc publicKeyToken=31bf3856ad364e35 /bindingRedirect oldVersion=1.0.0.0-5.2.2.0 newVersion=5.2.2.0 //dependentAssembly/assemblyBinding /runtime system.dataDbProviderFactoriesremove invariant=System.Data.SQLite/remove invariant=System.Data.SQLite.EF6 /add name=SQLite Data Provider invariant=System.Data.SQLite description=.Net Framework Data Provider for SQLite type=System.Data.SQLite.SQLiteFactory。

可以直接拷贝项目中的测试用的配置文件。

public class CustomerMap : EntityTypeConfigurationCustomer{public CustomerMap(){this.Property(o = o.UserName).HasColumnAnnotation(Index。

public class BaseEntity{public int Id { get; set; }}public class Customer : BaseEntity{public Customer(){this.Roles = new ListRole();}public string UserName { get; set; }public virtual ICollectionRole Roles { get; set; }}public class Role : BaseEntity{public Role(){this.Customers = new ListCustomer();}public virtual ICollectionCustomer Customers { get; set; }public string RoleName { get; set; }}public class Category : BaseEntity{public Category(){this.Children = new ListCategory();this.Posts = new ListPost();}public int? ParentId { get; set; }public virtual Category Parent { get; set; }public virtual ICollectionCategory Children { get; set; }public virtual ICollectionPost Posts { get; set; }}public class Post : BaseEntity{public virtual Category Category { get; set; }} 2.定义实体映射:CustomerMap、RoleMap、CategoryMap和PostMap作为关系表、索引的配置。

但实际上我只是在等待它的出现。

modelBuilder) { }protected override void Seed(SqliteDbContext context){context.SetCustomer().Add(new Customer { UserName = user + DateTime.Now.Ticks.ToString(),请访问 ?LinkId=301880 --configuration configSections!-- For more information on Entity Framework configuration, public class SqliteDbContext : DbContext{public SqliteDbContext(): base(DefaultConnection){}protected override void OnModelCreating(DbModelBuilder modelBuilder){modelBuilder.Conventions.RemovePluralizingTableNameConvention();modelBuilder.Configurations.AddFromAssembly(typeof(SqliteDbContext).Assembly);#if DEBUGDatabase.SetInitializer(new MyDbInitializer(Database.Connection.ConnectionString,从issues上看也就是几天的事, EntityFramework,直接使用SQL Server Compact性能又是问题, public class MvcApplication : System.Web.HttpApplication{protected void Application_Start(){using (var db = new SqliteDbContext()){}AreaRegistration.RegisterAllAreas();RouteConfig.RegisterRoutes(RouteTable.Routes);}} 查看生成的数据库:表映射、关系映射和索引都正确创建了, visit ?LinkID=237468 --section name=entityFramework type=System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, System.Data.SQLite //DbProviderFactories /system.data entityFrameworkdefaultConnectionFactory type=System.Data.Entity.Infrastructure.LocalDbConnectionFactory。

Roles = new ListRole { new Role { RoleName = user } } });context.SetPost().Add(new Post { Category = new Category() });base.Seed(context);}} 4.定义DbContext:此处必须配置PluralizingTableNameConvention,否则无法正常使用,。

本站内容来源于网络,如有侵权请与我们联系,我们会及时删除,我们深感抱歉!
注:本站所有信息仅供学习参考!
本文地址为 https://v30.fanwenzhu.com/sql/sqlite/11151.shtml

相关文章

风云图片

推荐阅读

返回sqlite频道首页